package org.nyt.medicalstore.controller;

import org.nyt.medicalstore.dto.SymptomDTO;
import org.nyt.medicalstore.model.Symptom;
import org.nyt.medicalstore.service.SymptomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/symptom")
public class SymptomController {
    @Autowired
    private SymptomService symptomService;

    private SymptomDTO toDTO(Symptom symptom) {
        SymptomDTO dto = new SymptomDTO();
        dto.setId(symptom.getId());
        dto.setName(symptom.getName());
        dto.setDescription(symptom.getDescription());
        return dto;
    }

    @PostMapping
    public SymptomDTO addSymptom(@RequestBody Symptom symptom) {
        return toDTO(symptomService.saveSymptom(symptom));
    }

    @GetMapping("/{id}")
    public SymptomDTO getSymptom(@PathVariable Long id) {
        return toDTO(symptomService.getSymptomById(id));
    }


    @DeleteMapping("/{id}")
    public void deleteSymptom(@PathVariable Long id) {
        symptomService.deleteSymptom(id);
    }
}
